import time

from selenium import webdriver
from selenium.webdriver.common.by import By
# 实例化驱动
driver = webdriver.Chrome()
# 打开百度页面
driver.get("https://www.baidu.com/")
# 全屏
driver.maximize_window()
# 隐式等待
driver.implicitly_wait(15)
# 点击设置按钮
driver.find_elements(By.NAME,"tj_settingicon")[1].click()
time.sleep(5)
# 点击搜索设置
driver.find_elements(By.CLASS_NAME,"set")[0].click()
time.sleep(5)
# 点击保存设置按钮
driver.find_element(By.CLASS_NAME,"prefpanelgo").click()
time.sleep(5)
# 先获取弹窗
alert = driver.switch_to.alert
# 点击弹窗中的确认
alert.accept()

# 等待一下
time.sleep(10)

"""
alert弹窗处理（弹窗是元素获取不到的，要这么处理）：
先获取当前所有的弹窗：driver.switch_to.alert
弹窗中确认按钮点击：alert.accept()
弹窗中点击取消：alert.dismiss()
"""
